<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="用户姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户手机号" prop="userPhone">
        <el-input
          v-model="queryParams.userPhone"
          placeholder="请输入用户手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="checkStatus">
        <el-select v-model="queryParams.checkStatus" placeholder="请选择审核状态" clearable size="small">
          <el-option label="--请选择--" value="" />
          <el-option v-for="item in checkStatusList" :key="item.code" :value="item.code" :label="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="申请时间" prop="queryCreateTimeStr">
        <el-date-picker
          v-model="queryParams.queryCreateTimeStr"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核时间" prop="queryCheckTimeStr">
        <el-date-picker
          v-model="queryParams.queryCheckTimeStr"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="支付时间" prop="queryPayTimeStr">
        <el-date-picker
          v-model="queryParams.queryPayTimeStr"
          type="daterange"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <!--<el-form-item label="审核状态描述" prop="checkStatusDescribe">
        <el-input
          v-model="queryParams.checkStatusDescribe"
          placeholder="请输入审核状态描述"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--<el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['pos:TUserDefaultInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="TUserDefaultInfoList" @selection-change="handleSelectionChange">
      /////支付状态（未支付/已支付）/趣工宝状态（未付款/处理中/已处理）/申请时间/操作时间
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="数据主键" align="center" prop="id" v-if="false"/>
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="手机号" align="center" prop="userPhone" />
      <el-table-column label="申请金额 " align="center" prop="transAmount" />
      <el-table-column label="到账金额" align="center" prop="withdrawAmount" />
      <el-table-column label="审核状态" align="center" prop="checkStatus" v-if="false"/>
      <el-table-column label="审核状态" align="center" prop="checkStatusShow" />
      <el-table-column label="趣工宝状态" align="center" prop="withdrawStatus" v-if="false"/>
      <el-table-column label="趣工宝状态" align="center" prop="withdrawStatusShow" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核时间" align="center" prop="checkStatusTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkStatusTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付时间" align="center" prop="withdrawStatusTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.withdrawStatusTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.checkStatus == '0' ? true : false"
            @click="handlePass(scope.row)"
            v-hasPermi="['pos:TUserDefaultInfo:edit']"
          >通过</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.checkStatus == '0' ? true : false"
            @click="handleRefuse(scope.row)"
            v-hasPermi="['pos:TUserDefaultInfo:remove']"
          >拒绝</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
            v-hasPermi="['pos:TUserDefaultInfo:query']"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户出入账信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="拒绝原因" prop="userId">
          <el-input v-model="form.checkStatusDescribe" placeholder="拒绝原因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {queryCheckStatus, listTUserDefaultInfo, getTUserDefaultInfo, delTUserDefaultInfo, addTUserDefaultInfo, updateTUserDefaultInfo, exportTUserDefaultInfo, checkPass, checkRefuse } from "@/api/pos/TUserDefaultInfo";

export default {
  name: "TUserDefaultInfo",
  data() {
    return {
      checkStatusList: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户出入账信息表格数据
      TUserDefaultInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userPhone: null,
        checkStatus: null,
        queryCreateTimeStr: null,
        queryCheckTimeStr: null,
        queryPayTimeStr: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getCheckStatus();
  },
  methods: {
    /** 查询用户出入账信息列表 */
    getList() {
      this.loading = true;
      listTUserDefaultInfo(this.queryParams).then(response => {
        this.TUserDefaultInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getCheckStatus(){
      queryCheckStatus().then(response => {
        this.checkStatusList = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        transType: null,
        transAmount: null,
        transOperType: null,
        goldType: null,
        brandId: null,
        orderId: null,
        createTime: null,
        updateUserId: null,
        updateTime: null,
        checkStatus: "0",
        checkStatusUserId: null,
        checkStatusTime: null,
        checkStatusDescribe: null,
        serviceChargeAmount: null,
        withdrawAmount: null,
        refereesUserId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTUserDefaultInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户出入账信息";
      });
    },
    /** 查询详情按钮操作 */
    handleDetail(row) {
      const id = row.id || this.ids[0];
      //console.log("----------", id);
      this.$router.push({path: "/TUserInfo/userManage/defaultDetail", query: {id: id, pageNum: this.queryParams.pageNum}});
    },
    /** 通过按钮操作 */
    handlePass(row){
      this.$confirm('确定审核通过并支付该笔申请吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.form.id = row.id || this.ids;
        checkPass(this.form).then(response => {
          this.$modal.msgSuccess("操作成功，请等待趣工宝支付结果");
          this.getList();
        });
      }).catch(() => {});
    },
    /** 拒绝按钮操作 */
    handleRefuse(row) {
      this.reset();
      const id = row.id || this.ids
      getTUserDefaultInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "拒绝支付";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          checkRefuse(this.form).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有用户出入账信息数据项？').then(() => {
        this.exportLoading = true;
        return exportTUserDefaultInfo(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
